﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MMeller.Net.MultiHashmap;

namespace HashmapExample
{
    class Program
    {
        private enum PersonKey
        {
            SURNAME, PESEL
        }

        private MultiHashmap<PersonKey, Person> multiHashmap;

        static void Main(string[] args)
        {
            Program p = new Program();
            p.initializeMap();
            p.loadElements();

            p.showExample();

            System.Console.ReadKey();

        }

        public void initializeMap()
        {
            List<HashmapType<PersonKey>> hashmapKeys = new List<HashmapType<PersonKey>>();
            hashmapKeys.Add(new HashmapType<PersonKey>(PersonKey.SURNAME, true));
            hashmapKeys.Add(new HashmapType<PersonKey>(PersonKey.PESEL, false));

            this.multiHashmap = new MultiHashmap<PersonKey, Person>(hashmapKeys);
        }

        public void loadElements()
        {
            Person p3 = new Person("James", "Velvick", "10252483034", true);
            Person p1 = new Person("Alice", "Smith", "65090796666", false);
            Person p2 = new Person("Bob", "Smith", "51051672711", true, (new Person[] { p3 }).ToList());

            loadElement(p3);
            loadElement(p1);
            loadElement(p2);
        }

        private void loadElement(Person p)
        {
            List<MultiHashmapElement<PersonKey, Person>> hashmapElements = new List<MultiHashmapElement<PersonKey, Person>>();
            hashmapElements.Add(new MultiHashmapElement<PersonKey, Person>(PersonKey.SURNAME, p.Surname, p));
            hashmapElements.Add(new MultiHashmapElement<PersonKey, Person>(PersonKey.PESEL, p.Pesel, p));
            this.multiHashmap.loadElement(hashmapElements);
        }

        public void showExample()
        {
            Person[] persons = this.multiHashmap.getElement(PersonKey.SURNAME, "Smith");
            foreach (Person person in persons)
            {
                System.Console.WriteLine(person);
            }
            persons = this.multiHashmap.getElement(PersonKey.PESEL, "10252483034");
            foreach (Person person in persons)
            {
                System.Console.WriteLine(person);
            }
        }
    }
}
